import type { MockMethod } from 'vite-plugin-mock'
import Mock from 'mockjs'

const mock: MockMethod[] = [
  {
    url: '/api/articles',
    method: 'get',
    response: () => {
      // 使用Mock生成随机列表数据
      return {
        code: 200,
        message: 'success',
        data: {
          list: Mock.mock({
            'items|5-10': [
              {
                'id|+1': 1,
                title: '@title(5, 10)',
                author: '@cname',
                'status|1': ['published', 'draft'],
                createTime: '@datetime'
              }
            ]
          }).items,
          total: 100
        }
      }
    }
  },
  {
    url: '/api/articles/:id',
    method: 'get',
    response: ({ url }:{ url:string }) => {
      // 从URL中提取ID
      const id = url?.split('/').pop()
      
      return {
        code: 200,
        message: 'success',
        data: {
          id,
          title: Mock.mock('@title(5, 10)'),
          content: Mock.mock('@paragraph(10, 20)'),
          author: Mock.mock('@cname'),
          createTime: Mock.mock('@datetime')
        }
      }
    }
  }
]

export default mock
    